
var jlang = {

	list : {

		comprehension : function (map, args) {
			var ret = [];
			this._comprehension(map, args, [], ret);
			return ret;
		},

		_comprehension : function (map, args, clos, ret) {
			if (args.length == 0)
				return ret.push(map.apply(this, clos));
			var arg = args.shift();
			if (arg instanceof Array)
			{
				for (var i = 0; i < arg.length; i ++)
				{
					var subClos = clos.slice(0);
					subClos.push(arg[i]);
					this._comprehension(map, args.slice(0), subClos, ret);
				}
				return;
			}
			if (arg instanceof Function)
			{
				if (arg.apply(this, clos))
					this._comprehension(map, args, clos, ret);
				return;
			}
			alert("Invalid comprehension list arg : " + arg);
		}
	}
};
